﻿CREATE TABLE [dbo].[Flight]
(
	Code nvarchar(10) NOT NULL CONSTRAINT PK_Flight PRIMARY KEY, 
	ShareFlightCode nvarchar(10) NULL,
	Segment int NOT NULL CONSTRAINT FK_Fligth_Segment REFERENCES Segment(Id),
	Operator varchar(10) NOT NULL CONSTRAINT FK_Flight_Operator REFERENCES Operator(Code),
	DepartureTime DateTime,
	ArrivalTime DateTime,
	ScheduleDeparture DateTime NOT NULL,
	ScheduleArrival DateTime NOT NULL CONSTRAINT CK_ScheduleTime CHECK(ScheduleArrival > ScheduleDeparture),
	[Status] int NOT NULL CONSTRAINT FK_Flight_FlightStatus REFERENCES FlightStatus(Id)
)